import request from "@/utils/request";
import { BaseResponse } from "@/api/types/baseResponse";
import {
  AttendanceResponse,
  AttendanceStatusRequest,
} from "@/api/types/attendance";


interface requestData{
  count: string;
    code?:string
    data?:any
    msg?:string
  }


//查
export function getAttendanceInfo(val: any) {
  return request({
    url: `/kaoqin/kaoqin?month=${val}`,
    method: "get",
  });
}

//修改
export function updateAttendanceInfo(data: any) {
  return request({
    url: "/kaoqin/kaoqin",
    method: "put",
    data,
  });
}

// 查询考勤信息的超时时间，单位：毫秒
const queryTimeout = 20000;

// 根据考勤组ID和月份查询考勤信息
export async function getAttendancesByAttendanceGroupIdAndMouth(
  attendanceGroupId: number,
  month: string
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: { groupid: attendanceGroupId, month },
    timeout: queryTimeout,
  });
}

// 根据考勤组ID、月份分页查询考勤信息
export async function getAttendancesByAttendanceGroupIdAndMonthAndPages(
  attendanceGroupId: number,
  month: string,
  pageNumber: number,
  pageSize: number,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      groupid: attendanceGroupId,
      month,
      page: pageNumber,
      per_page: pageSize,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 根据月份查询考勤信息
export async function getAttendancesByMonth(month: string) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: { month },
    timeout: queryTimeout,
  });
}

// 根据月份分页查询考勤信息
export async function getAttendancesByMonthAndPages(
  month: string,
  pageNumber: number,
  pageSize: number,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: { month, page: pageNumber, per_page: pageSize, is_leave },
    timeout: queryTimeout,
  });
}

// 根据门店ID、月份查询考勤信息
export async function getAttendancesByShopIdAndMonth(
  shopId: number,
  month: string
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: { shopid: shopId, month },
    timeout: queryTimeout,
  });
}

// 根据门店ID、月份分页查询考勤信息
export async function getAttendancesByShopIdAndMonthAndPages(
  shopId: number,
  month: string,
  pageNumber: number,
  pageSize: number,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      shopid: shopId,
      month,
      page: pageNumber,
      per_page: pageSize,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 根据月份分页查询清洁工的考勤信息
export async function getAttendancesOfCleanersByMonthAndPages(
  month: string,
  pageNumber: number,
  pageSize: number,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      cleaner: 1,
      month,
      page: pageNumber,
      per_page: pageSize,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 根据月份分页查询全职人员的考勤信息
export async function getAttendancesOfFullTimeEmployeesByMonthAndPages(
  month: string,
  pageNumber: number,
  pageSize: number,
  shopId: any,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      full: 1,
      month,
      page: pageNumber,
      per_page: pageSize,
      shop_id: shopId,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 根据月份分页查询办公室的考勤信息
export async function getAttendancesOfOfficeByMonthAndPages(
  month: string,
  pageNumber: number,
  pageSize: number,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      office: 1,
      month,
      page: pageNumber,
      per_page: pageSize,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 根据月份分页查询兼职人员的考勤信息
export async function getAttendancesOfPartTimeEmployeesByMonthAndPages(
  month: string,
  pageNumber: number,
  pageSize: number,
  shopId: any,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      part: 1,
      month,
      page: pageNumber,
      per_page: pageSize,
      shop_id: shopId,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 根据月份分页查询高级店长的考勤信息
export async function getAttendancesOfShopManagersByMonthAndPages(
  month: string,
  pageNumber: number,
  pageSize: number,
  is_leave: any
) {
  return await request<
    BaseResponse<AttendanceResponse[]>,
    BaseResponse<AttendanceResponse[]>
  >({
    url: "/kaoqin/kaoqin",
    params: {
      supermanager: 1,
      month,
      page: pageNumber,
      per_page: pageSize,
      is_leave,
    },
    timeout: queryTimeout,
  });
}

// 更新考勤明细状态
export async function updateAttendanceStatus(data: AttendanceStatusRequest,yearMonthDay:any) {
  data.kaoqin_time=`${yearMonthDay} ${data.kaoqin_time}`

  return await request<BaseResponse<undefined>, BaseResponse<undefined>>({
    url: "/kaoqin/kaoqin",
    method: "PUT",
    data,
  });
}

//查考勤明细
export function getAttendancecheck(data: any) {
  return request<requestData,requestData>({
    url: "/cal/check",
    method: "get",
    params: data,
  });
}

//重算考勤
export function getKaoqinBackcal(data: any) {
  return request<requestData,requestData>({
    url: "/kaoqin/backcal",
    method: "get",
    params: data,
  });
}

export function getPayrollGeneration(data: any) {
  return request<requestData,requestData>({
    url: "/kaoqin/genmoney",
    method: "get",
    params: data,
  });
}
